package com.example.fido2013;

import java.net.URI;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.content.Context;

public class APICallDogvestsArrayNoAsync{
	
	String sessionName;
	String sessionId;
	
	public APICallDogvestsArrayNoAsync(String sessionName, String sessionId) {
		this.sessionName = sessionName;
		this.sessionId = sessionId;
	}
	
	public ArrayList<JSONObject> getDogvestsArrayNoAsync(){
		String apiLocation = "http://dev.m.gatech.edu/d/vkrishnan35/w/fidocpy/c/api/updatevestslocation/";
		ArrayList<JSONObject> list = new ArrayList<JSONObject>();

		try {
			URI api = new URI(apiLocation);
			HttpClient client = new DefaultHttpClient();
			HttpGet request = new HttpGet();
			request.setURI(api);

			request.setHeader("Cookie", sessionName + "=" + sessionId);

			HttpResponse response = client.execute(request);
			HttpEntity entity = response.getEntity();
			String str = EntityUtils.toString(entity);

			try {
				JSONArray JsonArrayForResult = new JSONArray(str);

				for (int i = 0; i < JsonArrayForResult.length(); i++) {
					JSONObject jsonObject = JsonArrayForResult.getJSONObject(i);
					list.add(jsonObject);
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
}
